import 'package:flutter/material.dart';
import 'package:im_app/im/page/sub/GroupAddPage.dart';

import '../../../util/ImConstant.dart';
import '../../bloc/GroupAddCubit.dart';

AppBar createSessionAppBar(BuildContext context, String title) {
  return AppBar(
    title: Text(
      title,
      style: const TextStyle(color: ImConstant.IM_TEXT_COLOR, fontSize: ImConstant.IM_DEFAULT_SIZE),
    ),
    toolbarHeight: ImConstant.IM_APP_BAR_HEIGTH,
    centerTitle: true,
    elevation: 0.5,
    backgroundColor: ImConstant.IM_MAIN_BACKGROUND_COLOR,
    automaticallyImplyLeading: false,
    actions: [
      IconButton(
        icon: const Icon(Icons.search, color: ImConstant.IM_TEXT_COLOR,),
        tooltip: '查询',
        onPressed: () {
          Navigator.of(context).pushNamed("/ContentSearchPage");
        },
      ),
      MenuAnchor(
        builder: (BuildContext context, MenuController controller, Widget? child,) {
          return IconButton(
            icon: const Icon(Icons.add_circle_outline, color: ImConstant.IM_TEXT_COLOR,),
            tooltip: '',
            onPressed: () {
              if (controller.isOpen) {
                controller.close();
              } else {
                controller.open();
              }
            },
          );
        },
        style: const MenuStyle(
          backgroundColor: WidgetStatePropertyAll<Color>(Colors.black87),
          surfaceTintColor: WidgetStatePropertyAll<Color>(Colors.white),
          visualDensity: VisualDensity(horizontal: 1),
          alignment: Alignment.bottomLeft,
        ),
        menuChildren: [
          MenuItemButton(
            leadingIcon: const Icon(Icons.person_2_sharp, color: Colors.white,),
            onPressed: () {
              // Navigator.of(context).pushNamed("/GroupAddPage");
              Navigator.of(context).push(MaterialPageRoute(builder: (context){
                return buildGroupCubit(null, const GroupAddPage());
              }));
            },
            child:  const Text('发起群聊', style: TextStyle(color: Colors.white),),
          ),
          const MenuItemButton(
            leadingIcon: Icon(
              Icons.scanner_sharp,
              color: Colors.white,
            ),
            child: Text('扫一扫', style: TextStyle(color: Colors.white)),
          ),
        ],
      ),
    ],
  );
}

final NewsAppBar = AppBar(
  title: const Text('发现', style: TextStyle(color: ImConstant.IM_TEXT_COLOR),),
  toolbarHeight: ImConstant.IM_APP_BAR_HEIGTH,
  elevation: 0.5,
  // brightness: Brightness.light,
  backgroundColor: ImConstant.IM_MAIN_BACKGROUND_COLOR,
  automaticallyImplyLeading: false,
  actions: [
    IconButton(
      icon: const Icon(
        Icons.search,
        color: ImConstant.IM_TEXT_COLOR,
      ),
      tooltip: '查询',
      onPressed: () {},
    ),
    IconButton(
      icon: const Icon(
        Icons.add_circle_outline,
        color: ImConstant.IM_TEXT_COLOR,
      ),
      tooltip: '',
      onPressed: () {},
    )
  ],
);

final MeAppBar = AppBar(
  title: const Text(
    '我',
    style: TextStyle(color: ImConstant.IM_TEXT_COLOR, fontSize: ImConstant.IM_DEFAULT_SIZE),
  ),
  toolbarHeight: ImConstant.IM_APP_BAR_HEIGTH,
  elevation: 0.5,
  backgroundColor: ImConstant.IM_RESERVE_BACKGROUND_COLOR,
  automaticallyImplyLeading: false,
);
